package elevatronic.view.right.parameter;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import elevatronic.Elevatronic;


/**
 * 
 * @author Benjamin CORNEC
 * slide control for speed, by delay change
 *
 */
public class SpeedSliderDelayView extends SpeedSliderView {
	private static final long serialVersionUID = 7974590739034494043L;
	public static final int INIT=75;

	
	//facilitators for the delay
	public int getDelay(){
		return Elevatronic.getSingleton().getDelayTime();
	}	
	public void setDelay(int delay){
		Elevatronic.getSingleton().setDelayTime(delay);
	}
	
	//save the delay number
	private int delay;
	public void setDelayValue(int delay){
		this.delay=delay;
	}
	public int getDelayValue(){
		return delay;
	}
	
	/**
	 * Constructor
	 * @param width width of the slider
	 * @param height height of the slider
	 */
	public SpeedSliderDelayView(int width, int height) {
		super(width, height,0, 100, INIT);
		
		addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent arg0) {
				int delay=convert(getValue());
				setDelay(delay);
				setDelayValue(delay);
			}
	    });
	}

	
	public static int convert(int _value){
		return (_value*_value*_value)/1000+1;
	}
}
